<template>
  <div>
    <div class="toolbar">
      <el-form :inline="true" :model="q" size="mini">

        <el-form-item label="操作人:">
          <el-select v-model="q.user_id" filterable clearable placeholder="请选择">
            <!-- <el-option label="所有" :value=null></el-option> -->
            <el-option v-for="item in userList" :key="item.id" :label="item.name" :value="item.id"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="问题类型:">
          <el-select v-model="q.type_id" clearable placeholder="请选择">
            <!-- <el-option label="所有" :value=null></el-option> -->
            <el-option v-for="item in problemsTypeList" :key="item.id" :label="item.desc" :value="item.id"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="日期:">
          <el-date-picker v-model="q.day_start" value-format="yyyy-MM-dd" type="date" placeholder="选择日期时间">
          </el-date-picker>
          <span>-</span>
          <el-date-picker v-model="q.day_end" value-format="yyyy-MM-dd" type="date" placeholder="选择日期时间">
          </el-date-picker>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="query">查询</el-button>
          <el-button type="danger" @click="reload">重置</el-button>
          <el-button size="mini" @click="downloadData" type="primary" icon="el-icon-download">导出数据</el-button>
        </el-form-item>
      </el-form>
    </div>
    <el-table :data="DataTtl" size="mini" stripe border fit highlight-current-row>
      <el-table-column width="100">总计</el-table-column>
      <el-table-column prop="ttl_admin_count" label="接单人数"></el-table-column>
      <el-table-column prop="ttl_order_count" label="总单量"></el-table-column>
      <el-table-column prop="ttl_finish_count" label="已处理数量"></el-table-column>
      <el-table-column prop="ttl_wait_count" label="待处理数量"></el-table-column>
      <el-table-column prop="ttl_avg_process_time" label="平均处理时长（s）" min-width="110">
        <template slot-scope="scope">
          <span v-if="scope.row.ttl_avg_process_time">{{scope.row.ttl_avg_process_time.toFixed(2)}}</span><span
            v-else>0</span>
        </template>
      </el-table-column>
      <el-table-column prop="ttl_comment_good_count" label="满意数量"></el-table-column>
      <el-table-column prop="ttl_comment_bad_count" label="不满意数量"></el-table-column>
      <el-table-column prop="ttl_good_percent" label="满意度">
        <template slot-scope="scope">
          <span v-if="scope.row.ttl_good_percent">{{Number(scope.row.ttl_good_percent*100).toFixed(2)+"%"}}</span><span
            v-else>0</span>
        </template>
      </el-table-column>
      <el-table-column prop="ttl_quality_pass_count" label="质检合格数量" min-width="100"></el-table-column>
      <el-table-column prop="ttl_quality_unpass_count" label="质检不合格数量" min-width="110"></el-table-column>
    </el-table>
    <br />
    <el-table class="el-calendar-table" :data="listData.items" v-loading.body="listLoading" size="mini" stripe border
      fit highlight-current-row @selection-change="handleSelectionChange">
      <el-table-column prop="day" label="日期" width="130">
      </el-table-column>
      <el-table-column prop="user.name" label="操作人" width="210">
      </el-table-column>
      <el-table-column width="160" prop="type.desc" label="问题类型">
      </el-table-column>
      <el-table-column width="100" prop="ttl_order_count" label="总单量">
        <template slot-scope="scope">{{scope.row.finish_count+scope.row.wait_count}}</template>
      </el-table-column>
      <el-table-column width="100" prop="finish_count" label="已处理数量">
      </el-table-column>
      <el-table-column width="100" prop="wait_count" label="待处理数量">
      </el-table-column>
      <el-table-column width="130" prop="avg_process_time" label="平均处理时长（s）">
        <template slot-scope="scope">
          <span v-if="scope.row.avg_process_time">{{scope.row.avg_process_time.toFixed(2)}}</span><span v-else>0</span>
        </template>
      </el-table-column>
      <el-table-column width="100" prop="comment_good_count" label="满意数量">
      </el-table-column>
      <el-table-column width="110" prop="comment_bad_count" label="不满意数量">
      </el-table-column>
      <el-table-column prop="good_percent" label="满意度">
        <template slot-scope="scope">
          <span v-if="scope.row.good_percent">{{Number(scope.row.good_percent*100).toFixed(1)+"%"}}</span><span
            v-else>0</span>
        </template>
      </el-table-column>
      <el-table-column min-width="110" prop="quality_pass_count" label="质检合格数量">
      </el-table-column>
      <el-table-column min-width="110" prop="quality_unpass_count" label="质检不合格数量">
      </el-table-column>
    </el-table>
    <div class="pagination">
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="q.page_no"
        :page-sizes="$store.state.app.pageSizeArr" :page-size="q.page_size"
        layout="total, sizes, prev, pager, next, jumper" :total="listData.total">
      </el-pagination>
    </div>

  </div>
</template>

<script>
import { getPerformanceList, getProblemsList, getuserList, getPerformanceTTlList, getPerformanceDownLoad } from '@/api'
import { queryFilter } from "@/utils/patch";

export default {
  name: "index",
  data () {
    return {
      show_id: null,
      listData: {},
      q: { page_size: 30, page_no: 1 },
      listLoading: false,
      showUpdate: false,
      problemsTypeList: [],
      Timetype: true,
      working: true,
      userList: [],
      DataTtl: [],
    }
  },
  created () {
    this.getList()
    this.getProblemsList()
    this.getuserList()
  },
  methods: {
    downloadData () {
      let queryObj = queryFilter(this.q)
      let data = Object.assign({}, queryObj, { to_export_file: true })
      getPerformanceDownLoad(data).then(res => {
        if (res.status === 0) {
          window.location.href = window.location.origin + res.data.url
        }
      })
    },
    getuserList () {
      getuserList().then(res => {
        if (res.status === 0) {
          this.userList = res.data
        }
      })
    },
    getProblemsList () {
      getProblemsList().then(res => {
        if (res.status === 0) {
          this.problemsTypeList = res.data.items
        }
      })
    },
    Details (row) {
      this.show_id = row.id
      this.showUpdate = true
    },
    // sendMsg (row) {

    // },
    query () {
      this.q = Object.assign(this.q, { page_no: 1, page_size: 30 })
      this.getList()
    },
    reload () {
      this.q = { page_no: 1, page_size: 30 }
      this.getList()
    },
    handleSizeChange (val) {
      this.q.page_size = val
      this.getList()
    },
    handleCurrentChange (val) {
      this.q.page_no = val
      this.getList()
    },

    getList () {
      let queryObj = queryFilter(this.q)
      getPerformanceList(queryObj).then(res => {
        if (res.status === 0) {
          this.listLoading = false
          this.listData = res.data
        }
      })
      getPerformanceTTlList(queryObj).then(res => {
        if (res.status === 0) {
          this.listLoading = false
          this.DataTtl = [res.data]

        }
      })
    },
    handleSelectionChange (sel) {
      console.log(sel)
    },
    toggleTimetype () {
      if (this.Timetype) {
        delete this.q.created_at_begin
        delete this.q.created_at_end
        this.Timetype = !this.Timetype
      } else {
        delete this.q.updated_at_begin
        delete this.q.updated_at_end
        this.Timetype = !this.Timetype
      }
    },
  },
  watch: {
    showUpdate () {
      if (!this.showUpdate) {
        this.getList()
      }
    }
  }
}
</script>

<style scoped>
.el-form-item__label {
  width: 100px !important;
}
</style>
